home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
ulib
/
pof2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
816b
|
39 lines
/***********************************************************************
* $Id: pof2.c,v 0.80 1994/02/24 09:48:11 zhao Exp $
*
*. Copyright(c) 1993,1994 by T.C. Zhao
* All rights reserved.
*.
* get the closest power of 2 no smaller than n
***********************************************************************/
#if !defined(lint) && defined(F_ID)
char *id_pof2 = "$Id: pof2.c,v 0.80 1994/02/24 09:48:11 zhao Exp $";
#endif
#include "ulib.h"
/* speed is of no concern */
unsigned int
power_of_2(register unsigned int n)
{
register unsigned int i = 1;
if (n == 0)
return 0;
while ((1 << i) < n)
i++;
return 1 << i;
}
#ifdef TEST
#include <stdio.h>
main()
{
int i;
while (fscanf(stdin, "%d", &i) == 1)
printf("Input= %d Pof2=%d\n", i, power_of_2(i));
return 0;
}
#endif